<?php
/**
 * Smart Library - Smart Framework
 * http://smart-framework.highet.eu
 *
 * @package    SmartL_Acl
 * @copyright  Copyright (c) 2005-2008 Smart Framework team - Stepan Sindelar, Vojtech Vit
 * @license    http://www.opensource.org/licenses/bsd-license.php	New BSD License
 */

/**
 * Static class with static method that is helper for authorizing.
 * 
 * @package SmartL_Acl
 */
class SmartL_Acl {
	/**
	 * Indicates if given role is authorized.
	 * It searches role in permitted and in restricted roles.
	 * Alias * in roles lists is allowed.
	 * Default is True.
	 *
	 * @param string $role
	 * @param array[numeric]=>string $permittedRoles
	 * @param array[numeric]=>string $restrictedRoles
	 * @return boolean
	 */
	static public function isAuthorized($roleName, $permittedRoles, $restrictedRoles = null) {
		$result = true;
		if (array_search ( $roleName, $permittedRoles ) !== false) {
			return true;
		}
		if (array_search ( $roleName, $restrictedRoles ) !== false) {
			return false;
		}
		
		if (array_search ( "*", $permittedRoles ) !== false) {
			return true;
		}
		if (array_search ( "*", $restrictedRoles ) !== false) {
			return false;
		}
		
		return $result;
	}
}